/** 
*
* @author  jiwf /li
* @date 创建时间：2016年10月21日 下午10:30:53 
* @version 1.0 
* @since  
*  
*/
package com.xbstar.web;

import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xbstar.bean.RouteInfo;
import com.xbstar.dao.RouteInfoRepository;
import com.xbstar.tools.BeanUtils;

@RestController
@RequestMapping("/way")
@CrossOrigin
public class WayController {
	@Autowired
	RouteInfoRepository routeRe;
	@RequestMapping("/add")
	public String addWay(@RequestParam("name")String name,@RequestParam("destinationId")Long destinationId,HttpServletRequest req){
		JSONObject json=new JSONObject();
		RouteInfo routeinfo=new RouteInfo();
		try {
			routeinfo=BeanUtils.copyRequestToObj(routeinfo, req);
		} catch (Exception e) {
			e.printStackTrace();
		}
		routeinfo.setName(name);
		routeinfo.setDestinationId(destinationId);
		try {
			routeRe.save(routeinfo);
			json.put(UserPackage.STATUS, UserPackage.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			json.put(UserPackage.STATUS, UserPackage.SERVER_ERROR);
		}
		return json.toString();
	}

}

